package com.guoxin.concurrentcy.chapter6;

/**
 * @author guoxin
 * @date 2019/7/2
 */
@SuppressWarnings("all")
public class ThreadInterruptJoin {

    public static void main(String[] args) {
        Thread t1 = new Thread(){
            @Override
            public void run() {
                while (true){}
            }
        };
        t1.start();
        Thread main = Thread.currentThread();
        Thread t2 = new Thread(){
            @Override
            public void run() {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                main.interrupt();
                System.out.println("interrupt");
            }
        };
        t2.start();

        try {
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
